#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
教学楼映射模块
负责教学楼名称和代码的转换
"""

from typing import Dict

# 教学楼名称映射
BUILDING_NAME_MAP: Dict[str, str] = {
    "13": "第十七号教学楼",
    "1": "思源楼",
    "2": "思源西楼",
    "3": "思源东楼",
    "4": "第九教学楼",
    "5": "第八教学楼",
    "6": "第五教学楼",
    "7": "第二教学楼",
    "11": "逸夫教学楼",
    "12": "机械楼",
    "9": "东区二教",
    "8": "东区一教",
    "10": "东教三楼",
    "103": "科技楼",
    "107": "知行楼"
}

# 教学楼名称映射（名称 -> 代码）
BUILDING_CODE_MAP: Dict[str, str] = {
    "第十七号教学楼": "13", "十七教": "13",
    "思源楼": "1", "思源": "1",
    "思源西楼": "2", "思源西": "2",
    "思源东楼": "3", "思源东": "3",
    "第九教学楼": "4", "九教": "4",
    "第八教学楼": "5", "八教": "5",
    "第五教学楼": "6", "五教": "6",
    "第二教学楼": "7", "二教": "7",
    "逸夫教学楼": "11", "逸夫": "11",
    "机械楼": "12", "机械": "12",
    "东区二教": "9", "东二教": "9",
    "东区一教": "8", "东一教": "8",
    "东教三楼": "10", "东三教": "10",
    "科技楼": "103",
    "知行楼": "107"
}


class BuildingMapper:
    """教学楼映射器"""

    @staticmethod
    def normalize_building_code(building_code: str) -> str:
        """标准化教学楼代码，支持名称和编号的转换"""
        # 如果已经是数字编号，直接返回
        if building_code.isdigit():
            return building_code

        # 如果是名称，转换为编号
        return BUILDING_CODE_MAP.get(building_code, building_code)

    @staticmethod
    def get_building_name(building_code: str) -> str:
        """根据教学楼代码获取名称"""
        return BUILDING_NAME_MAP.get(building_code, f"教学楼{building_code}")

    @staticmethod
    def get_building_code(building_name: str) -> str:
        """根据教学楼名称获取代码"""
        return BUILDING_CODE_MAP.get(building_name, building_name)

    @staticmethod
    def get_all_buildings() -> Dict[str, str]:
        """获取所有教学楼映射"""
        return BUILDING_NAME_MAP.copy()

    @staticmethod
    def validate_building_code(building_code: str) -> bool:
        """验证教学楼代码是否有效"""
        normalized_code = BuildingMapper.normalize_building_code(building_code)
        return normalized_code in BUILDING_NAME_MAP